<template>
	<view class="container">
		<star-nav :type="1" :listType="3" title="交易市场" icon="/static/icon-images/cart.png"></star-nav>
		<view class="content">
			<!-- 导航条 -->
			<tabs @success="handleTab"></tabs>
			<!-- 商品列表 -->
			<product ref="productRef"></product>
		</view>
	</view>
</template>

<script>
	import {userAdvertising} from '@/api/index.js'
	import {myUser} from '@/api/my.js'
	import Vue from 'vue'
	import tabs from './components/tabs/index.vue'
	import product from './components/product/index.vue'
	export default {
		components:{
			tabs,
			product
		},
		data() {
			return {
				users:{},
				isItAdFree:false
			}
		},
		onLoad() {
			setTimeout(()=>{
				this.getUser()
			},1000)
			setTimeout(()=>{
				this.$refs.productRef.setID(0)
			},400)
			//激励成功观看成功
			window.onRewardSuccess = () => {
				console.log('激励成功观看成功');
			} 
			//激励失败观看失败
			window.onRewardAdLoadError = (code, msg) => {
				console.log('激励视频观看失败');
			} 
		},
		onShow() {
			this.getUserAdvertising()
		},
		methods: {
			// 是否免广告
			async getUserAdvertising(){
				let res = await userAdvertising()
				this.isItAdFree = res.data
			},
			async getUser(){
				let res = await myUser()
				let data = res.data
				if(!this.isItAdFree){
					window.android.showRewardAd(data.userid,data.idNumber)
				}
			},
			handleTab(id){
				this.$refs.productRef.setID(id)
			}
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		// height: 100vh;
		background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
	}
	
	.content{
		padding: 20rpx;
	}
	
	.mt-20{
		margin-top: 20rpx;
	}
	.container{
		// width: 100%;
		// height: 100vh;
		// display: flex;
		// flex-direction: column;
	}
</style>